package xyz.zhouzhousag.server.pojo.entity;
/**
 * Description:
 * <p>
 * ClassName: BaseResponse
 * date: 2021/9/26 18:43
 *
 * @author Yin.Liu
 * @version 1.0
 * @since JDK 1.8
 */

import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName BaseResponse
 * @Description Json响应
 * @Author Yin.Liu8
 * @Date 2021/9/26 18:43
 * @Version 1.0
 */
@Data
public class BaseResponse<T> implements Serializable {
    public static final String SUCCESS = "success";
    public static final String FAIL = "fail";
    private static final long serialVersionUID = 1L;

    /**
     * 状态码
     */
    private String code;

    /**
     * 消息内容
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    public BaseResponse() {
        this("not-initialized", null, null);
    }

    public BaseResponse(String code) {
        this(code, null, null);
    }

    public BaseResponse(String code, T data) {
        this(code, data, null);
    }

    public BaseResponse(String code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse("success", data);
    }

    public static BaseResponse success() {
        return success(null);
    }

    public static BaseResponse fail(String message) {
        return new BaseResponse("fail", null, message);
    }

    public static BaseResponse fail(Throwable t) {
        return fail(t.getMessage());
    }
}
